package com.hackerrank.www.javap.Strings;

import java.util.Scanner;

/**
 * Created by 27340 on 2017/5/14.
 */
public class StringCompare {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int sublength = sc.nextInt();
        int length = str.length();
        String max = "";
        String min = "";
        int loopTime = length-sublength+1;
        for (int index=0;index<loopTime;index++){
            String temp = str.substring(index,index+sublength);
            if(max.equals("")){
                max = temp;
            }
            if(min.equals("")){
                min = temp;
            }
            if(min.compareTo(temp)>0){
                min = temp;
            }
            if(max.compareTo(temp)<0){
                max = temp;
            }
        }
        System.out.println(min);
        System.out.println(max);
    }
}
